package Practice1_Collection.P2_Equals;

import java.util.Objects;

public class Person {
    String name;
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o){
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Person person = (Person) o;
        return Objects.equals(name, person.name);
    }

//    @Override
//    public boolean equals(Object o){
//        if (o instanceof Person) {
//            Person person = (Person) o;
//            boolean nameEquals = false;
//            if (this.name == null && person.name == null) {
//                nameEquals = true;
//            }
//            if(this.name != null){
//                nameEquals = this.name.equals(person.name);
//            }
//            return nameEquals;
//        }
//        return false;
//    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public Person(String name) {
        this.name = name;
    }
}
